-
Notifications
You must be signed in to change notification settings - Fork 794
[SYCL][CMAKE] Fix _FORTIFY_SOURCE=3 #19268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SYCL][CMAKE] Fix _FORTIFY_SOURCE=3 #19268
Conversation
The problem here is that the macro is actually handled by glibc and value `3` isn't supported with older compiler/glibc combinations, causing warnings about the macro redefinition. We still have to support older compilers/glibc and therefore as a temporary solution, reverting `_FORTIFY_SOURCE` back to `2` to avoid build issues with `-Werror`.
@@ -167,18 +167,18 @@ macro(append_common_extra_security_flags) | |||
if(LLVM_ON_UNIX) | |||
# Fortify Source (strongly recommended): | |||
if(CMAKE_BUILD_TYPE STREQUAL "Debug") | |||
message(WARNING "-D_FORTIFY_SOURCE=3 can only be used with optimization.") | |||
message(WARNING "-D_FORTIFY_SOURCE=3 is not supported.") | |||
message(WARNING "-D_FORTIFY_SOURCE=2 can only be used with optimization.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can detect what compiler we can use 3
on and use that and use 2
otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can detect what compiler we can use
3
on and use that and use2
otherwise?
Theoretically, but it is not clear which exact versions are "good" and which ones are "bad". It seems like gcc 12 is the first "good" (link), but I'm not sure about clang
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc says There has been compiler support for this builtin in [Clang](https://clang.llvm.org/) for some time
so maybe we can just ignore it/check for some really old version?
If 3
has some benefit IMO we should try to add a check to see if we can use it if it's not too complicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
075da8c introduces the check. I also had to uplift _FORTIFY_SOURCE
in the Unified Runtime to avoid macro redefinition. We set it globally, but UR also sets it locally, because it is intended to buildable standalone.
I tried to uplift _FORTIFY_SOURCE
in UR in #19236 and this is how I detected the issue with "bad" gcc, so we will see now if the suggested check works.
@intel/unified-runtime-reviewers, could you please take a look? |
The problem here is that the macro is actually handled by glibc and value `3` isn't supported with older compiler/glibc combinations, causing warnings about the macro redefinition. We still have to support older compilers/glibc and therefore two changes were made: - UR skips setting their own `_FORTIFY_SOURCE` in favor of a global one if it is built as part of LLVM (i.e. not standalone) - Before setting `_FORTIFY_SOURCE` globally we check the compiler and fallback to value `2` for older gcc
This PR contains several cherry-picks and some unique changes which have not been applied to the `sycl` branch yet. The intent of this PR is to enable as much (quickly) possible hardening flags to be in better compliance with our SDL requirements. The main thing this PR is after are things like immediate bindings, fortify source, stack protection and `relro`. The thing that this PR is **not** after are extra warning flags - some of them we can't apply globally because LLVM itself isn't warning free, some of them we can't apply even locally to SYCL RT because we haven't fixed corresponding warnings yet. Patches which were cherry-picked from the `sycl` branch: - [SYCL] Fix AddSecurityFlags having no side effects (#17690) - Patch-By: Alexey Sachkov <[email protected]> - [SYCL] Refresh hardening flags applied to the project (#18398) - Patch-By: Nikita Kornev <[email protected]> - [SYCL][CMAKE] Refactor -fPIE handling (#19235) - Patch-By: Alexey Sachkov <[email protected]> - [SYCL][CMAKE] Drop nodlopen from hardening flags (#19357) - Patch-By: Alexey Sachkov <[email protected]> - [SYCL][CMAKE] Fix _FORTIFY_SOURCE=3 (#19268) - Patch-By: Alexey Sachkov <[email protected]> - [SYCL][CMake] Properly enable -pie hardening flag (#19447) - Patch-By: Alexey Sachkov <[email protected]> Additional changes which have **not** been applied to the `sycl` branch: - Adjusted `configure.py` to the new way of `-fPIE` handling - Dropped `/sdl` flag because LLVM isn't warning-free - it will be applied locally to SYCL RT in a separate PR against the `sycl` branch for future releases - Dropped `/analyze` flag because SYCL RT isn't warning-free - it will be applied locally to SYCL RT in a separate PR against the `sycl` branch for future releases
The problem here is that the macro is actually handled by glibc and value
3
isn't supported with older compiler/glibc combinations, causing warnings about the macro redefinition.We still have to support older compilers/glibc and therefore two changes were made:
_FORTIFY_SOURCE
in favor of a global one if it is built as part of LLVM (i.e. not standalone)_FORTIFY_SOURCE
globally we check the compiler and fallback to value2
for older gcc